package com.dehui.traders.ui.viewmodle;

import android.content.Context;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;

import com.dehui.traders.R;
import com.dehui.traders.adapter.OptionalStockAdapter;
import com.dehui.traders.adapter.RankListAdapter;
import com.dehui.traders.bean.OptionalStockBean;
import com.dehui.traders.bean.RankBean;
import com.dehui.traders.event.Events;
import com.dehui.traders.event.RxBus;
import com.dehui.traders.ui.activity.AddOptionalStockActivity;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * Created by hqq on 18.4.18.
 */

public class AddOptionalStockViewModel extends BaseViewModel implements OptionalStockAdapter.OnOptionalStockAdapterListener {

    public AddOptionalInterface addOptionalInterface;
    public ObservableList<OptionalStockBean> stockBeanObservableList = new ObservableArrayList<>();

    public OptionalStockAdapter stockAdapter = new OptionalStockAdapter(context,stockBeanObservableList,R.layout.list_item_add_optional_stock);

    public ObservableField<CommonAdapter> stockObservable = new ObservableField<>(stockAdapter);

    public BindingCommand cancelOnClick = new BindingCommand(()->{
        if (addOptionalInterface != null)
            addOptionalInterface.finishView();
    });

    public AddOptionalStockViewModel(Context context,AddOptionalInterface addOptionalInterface) {
        super(context);
        this.addOptionalInterface = addOptionalInterface;
        init();
    }

    private void init() {
        stockBeanObservableList.add(new OptionalStockBean("兴森科技","002345",null));
        stockBeanObservableList.add(new OptionalStockBean("华锋股份","002806",null));

        stockAdapter.setListener(this);
    }

    @Override
    public void addStock() {
        Events<Object> event = Events.just(null);
        RxBus.getInstance().post(event);
    }

    public interface AddOptionalInterface{
        void finishView();
    }


}
